var eCommand;
var eCommandForm;
var eUser;
var eHistory;
var eHistoryOptions;
//init();
function init()
{
	eUser=document.getElementById("user");
	if(eUser!=null)
	{
		eUser.focus();
		return;
	}
	eCommandForm=document.getElementById("commandform");
	eCommand=document.getElementById("command");
	eHistory=document.getElementById("historyblock");
	eHistoryOptions=document.getElementById("historyoptions");
	if(eCommand!=null)
	{
		eCommand.focus();
		return;
	}
}

function changedisplaystate(e)
{
	//alert(e.style.display);
	if(e.style.display=="none")
	{
		e.style.display="";
	}
	else
	{
		e.style.display="none";
	}
}
function displayhistory()
{
	changedisplaystate(eHistory);
	eCommand.focus();
}
function closehistory()
{
	eHistory.style.display="none";
	eCommand.focus();
}
function unlink(filename)
{
	var command;
	if(window.confirm("File "+filename+" will be deleted,are you sure?"))
	{
		command="unlink "+filename;
		runcommand(command);
	}
	
}
function rmdir(dirname)
{
	var command;
	if(window.confirm("Directory "+dirname+" will be deleted,are you sure?"))
	{
		if(window.confirm("Do you want to delete all files and directories in "+dirname+"?"))
		{
			command="rmdir "+dirname+" -r";
		}
		else
		{
			command="rmdir "+dirname;
		}
		runcommand(command);
	}
}
function rename(name)
{
	var command;
	var newname;
	newname=window.prompt("Rename "+name+" to",name);
	if(newname===null||newname===""||newname===false)
	{
		return false;
	}
	command="rename "+name+" "+newname;
	runcommand(command);
}
function copy(name)
{
	var command;
	var destname;
	destname=window.prompt("Copy "+name+" to",name);
	if(destname===null||destname===""||destname===false)
	{
		return false;
	}
	command="copy "+name+" "+destname;
	runcommand(command);
}
function copydir(name)
{
	var command;
	var destname;
	destname=window.prompt("Copy "+name+" to","");
	if(destname===null||destname===""||destname===false)
	{
		return false;
	}
	command="copydir "+name+" "+destname;
	runcommand(command);
}
function unzip(filename)
{
	var command;
	var dest;
	dest=window.prompt("Unzip "+filename+" to","");
	if(dest===null||dest===false)
	{
		return false;
	}
	command="unzip "+filename+" "+dest;
	runcommand(command);
}
function zip(dirname)
{
	var command;
	var dest;
	dest=window.prompt("Zip "+dirname+" to",dirname+".zip");
	if(dest===null||dest===false||dest==="")
	{
		return false;
	}
	command="zip "+dirname+" "+dest;
	runcommand(command);
}
function upload()
{
	var command;
	var dest;
	var filepath=document.getElementById("file").value;
	if(filepath.length==0)
	{
		return false;
	}
	dest=window.prompt("Upload "+filepath+" to",filename(filepath));
	if(dest===null||dest===false)
	{
		return false;
	}
	command="upload "+dest;
	runcommand(command);
}
function filename(filepath)
{
	var filename=filepath.replace(/\\/g,"/");
	var index=filename.lastIndexOf("/");
	return filename.substr(index+1);
}
function inserthistory(command)
{
	if(command!="")
		makecommand(command);
	closehistory();
}
function makecommand(command)
{
	eCommand.value=command;
}
function runcommand(command)
{
	eCommand.value=command;
	eCommandForm.submit();
}
